var BaseModel = require('../libs/baseModel.js');
var moment = require('moment');
var model = new BaseModel();

var _Schema = new model.Schema({
    company_id  : String,
    company_role: String,
    user_id     : String,
    employee_id : String,
    nickname    : String,
    nickname_en : String,
    avatar      : String,
    title       : String,
    idcard      : String,
    extConfig   : String,
    phoneno     : {type: String, default: ''},
    email       : {type: String, default: ''},
    created     : String,
    modified    : String
}, { versionKey: false });

_Schema.pre('save',function (next) {
    let nowTime = moment().format('YYYY-MM-DD HH:mm:ss');
    if(this.isNew){
        this.created = this.modified = nowTime;
    }else{
        this.modified = nowTime;
    }
    next();
});

model.schema = model.mongoose.model('company_users', _Schema);

module.exports = model;
